package cn.factorybox.item.utils;

import cn.factorybox.common.utils.DateFormatUtil;
import cn.factorybox.model.entity.DeviceData;
import cn.factorybox.model.entity.JudgeValue;

import java.util.*;

/**
 * @author flypig
 * @version 1.0
 * @date 2020-03-25 21:52
 */
public class JudgeAppDayData {

    public static List<Map<String,Object>> formatData(int type, List<DeviceData> datas, List<JudgeValue> list,String status) throws Exception {

        List<Map<String,Object>> day_details = new ArrayList<>();
        String[] names = {"fTemperature","fHumidity","fCarbonDioxide","fTvoc","fExhaust","fPressure","fPm"};

        Map<String,List<Double>> map = new HashMap<>();

        GregorianCalendar gregorianCalendar = new GregorianCalendar();
//        int hour = gregorianCalendar.get(Calendar.HOUR_OF_DAY);
//        int hour = 23;
        int num = 0;
        if (status.equals("day")) {
            num = gregorianCalendar.get(Calendar.HOUR_OF_DAY);
        } else if (status.equals("week")) {
            num = datas.size();
        }
        /**
         * 下面为旧代码，需要计算平均值版本
         */
//        for (String name : names) {
//            try {
//                List<Double> listdata = new ArrayList<>();
//                listdata =  EchartsUtils.getEchartsData(hour,1,datas,name);
//                map.put(name,listdata);
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//        }
//        List<DeviceData> deviceDatas = new ArrayList<>();
//        for (int i = 0; i < hour + 1; i = i + 1) {
//            // 循环转为List<DeviceData>
//            Map<String,Object> maps = new HashMap<>();
//            for (String name : names) {
////                List<Double> lists = map.get(name);
//                maps.put(name, map.get(name).get(i));
//            }
//            DeviceData deviceData = BeanMapUtils.mapToBean(maps,DeviceData.class);
//            deviceDatas.add(deviceData);
//        }

        for (int i = 0; i < datas.size(); i = i + 1) {
//            System.out.println(datas.get(i).toString());
            Map<String,Object> details = new HashMap<>();
            details.put("day_time", DateFormatUtil.formatTime(datas.get(i).getfCreateTime()));
            details.put("day_rank",datas.get(i).getResult());
            List<Map<String,Object>> day_data = JudgeAppData.formatData(datas.get(i),list,type);
            details.put("day_data",day_data);
            day_details.add(details);
        }
        return  day_details;
    }



}
